package com.hqyj.smvc.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.hqyj.smvc.mapper.EmployeeMapper;
import com.hqyj.smvc.mapper.IdcardMapper;
import com.hqyj.smvc.pojo.Employee;
import com.hqyj.smvc.pojo.Idcard;
import com.hqyj.smvc.service.IdcardService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("idcardService")
@Slf4j
public class IdcardServiceImpl implements IdcardService {
    @Autowired
    @Qualifier("idcardMapper")
    private IdcardMapper idcardMapper;
    @Autowired
    @Qualifier("employeeMapper")
    private EmployeeMapper employeeMapper;

    //分页查看身份证信息
    @Override
    public List<Idcard> showTheIdcard(int i){
        log.info("IdcardServiceImpl>>>showTheIdcard, start……");
        Page<Idcard> idcardPage = PageHelper.startPage(i, 3);
        List<Idcard> idcards = idcardMapper.selectIdcardList();
        log.info("IdcardServiceImpl>>>showTheIdcard, end……");
        return idcards;
    }

    //添加身份证
    @Override
    public void appendIdcard(Idcard idcard){
        log.info("IdcardServiceImpl>>>appendIdcard, start……");
        int i = idcardMapper.insertIdcard(idcard);
        int idcard_id = idcard.getIdcard_id();
        Employee employee = idcard.getEmployee();
        employee.setIdcard_id(idcard_id);
        employeeMapper.updateEmployeeInformation(employee);
        log.info("IdcardServiceImpl>>>appendIdcard, end……");
    }

    //根据删除的身份证删除员工
    @Override
    public int removeEmployee(int id){
        log.info("IdcardServiceImpl>>>removeEmployee, start……");
        int i1 = employeeMapper.deleteEmployee(id);
        int i = idcardMapper.deleteIdcard(id);
        log.info("IdcardServiceImpl>>>removeEmployee, end……");
        return i1;
    }

    //查询雇员信息
    @Override
    public Idcard demandIdcard(int id){
        log.info("IdcardServiceImpl>>>demandIdcard, start……");
        Idcard idcard = idcardMapper.selectIdcard(id);
        Employee employee = employeeMapper.selectEmployeeId(id);
        idcard.setEmployee(employee);
        log.info("IdcardServiceImpl>>>demandIdcard, end……");
        return idcard;
    }

    //编辑雇员
    @Override
    public void compileIdcard(Idcard idcard) {
        log.info("IdcardServiceImpl>>>compileIdcard, start……");
        int i = idcardMapper.updateIdcard(idcard);
        log.info("IdcardServiceImpl>>>compileIdcard, end……");
    }
}
